<?php

class MenuModule extends fvModule {
	
	function __construct () {
	    $moduleName = strtolower(substr(__CLASS__, 0, -6));

	    parent::__construct(fvSite::$fvConfig->get("modules.{$moduleName}.smarty.template"), 
	                        fvSite::$fvConfig->get("modules.{$moduleName}.smarty.compile"), 
	                        fvSite::$Layoult);
	}

	function showBlock($params) {
		$sitemenus = SitemenuManager::getInstance()->getAll("lang='".fvSite::$fvSession->get("lang")."'", "menu_order, id asc");
		foreach ($sitemenus as $key=>$sm){
			$sp = StaticPagesManager::getInstance()->getAll("tech_url='".$sm->url."' and lang='".fvSite::$fvSession->get("lang")."'");
			if ($sp)
				$submenus[$sm->getPk()] = StaticPagesManager::getInstance()->getAll("parent=".$sp[0]->getPk()." and lang='".fvSite::$fvSession->get("lang")."'", "menu_order, id asc");
		}
		$current = fvSite::$fvRequest->getRequestParameter("module");
		if (fvSite::$fvRequest->getRequestParameter("action")){
			$sp = StaticPagesManager::getInstance()->getAll("tech_url='".fvSite::$fvRequest->getRequestParameter("module")."' and lang='".fvSite::$fvSession->get("lang")."'", "menu_order, id desc");
			if ($ss = StaticPagesManager::getInstance()->getByPk($sp[0]->parent)){
				$current = $ss->tech_url;
			}
		}
		$this->__assign("sitemenus", $sitemenus);
		$this->__assign("submenus", $submenus);
		$this->__assign("current", $current);
	    return $this->__display("menu_block.tpl");
	}
	
	function showLeftblock($params) {
		$request = fvRequest::getInstance();
		$current = $request->getEscapedParameter("module");
		$StaticPage = StaticPagesManager::getInstance()->getAll("tech_url='".$current."' and lang='".fvSite::$fvSession->get("lang")."'");
		if ($StaticPage[0]){
			if ($StaticPage[0]->parent){
				$pages = StaticPagesManager::getInstance()->getAll("parent='".$StaticPage[0]->parent."' and lang='".fvSite::$fvSession->get("lang")."'", "menu_order, id asc");
			}
			else{
				$pages = StaticPagesManager::getInstance()->getAll("parent='".$StaticPage[0]->getPk()."' and lang='".fvSite::$fvSession->get("lang")."'", "menu_order, id asc");
			}
			if (count($pages)){
				$this->__assign("menus", $pages);
				$this->__assign("current", $current);
	    		return $this->__display("menu_leftblock.tpl");
			}
		}
	}
}

?>
